package com.ljq.nacos.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/test")
public class TestContorller {

    @NacosValue(value = "${nacos.value}",autoRefreshed = true)
    private String nacosConfigValue;

    @Value("${nacos.value2}")
    private String nacosConfigValue2;

    @NacosInjected
    private NamingService namingService;


    @GetMapping
    public String getValue(){
        return "读取到nacos配置中心配置："+nacosConfigValue;
    }

    @GetMapping("/register")
    public List<Instance> register() throws NacosException {
        String nameServer="testRegister"+Math.round(20);
        System.out.println(nameServer);
        return namingService.getAllInstances(nameServer);
    }
}
